#include<iostream>
using namespace std;
int isFib(int n)
{
    int a = 0;
    int b = 1;
    int c = a + b;
    while (c)
    {
        if (n == c)
        {
            return 1;
        }
        else if (c > n)
        {
            break;
        }
        a = b;
        b = c;
        c = a + b;
    }
    return 0;
}
int main()
{
    int n = 0;
    cin >> n;
    if (n == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    int count = 0;
    int _count = 0;
    int i = 0;
    for (i = n; i >= 0; i--)
    {
        if (isFib(i) == 1)
        {
            count = n - i;
            break;
        }
    }
    for (i = n; ; ++i)
    {
        if (isFib(i) == 1)
        {
            if (count > (i - n))
            {
                count = i - n;
                break;
            }
        }
        _count++;
        if (_count >= count)
        {
            break;
        }
    }
    cout << count << endl;
    return 0;
}